<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="UTF-8">
		<title>LingPowerAI</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script type="text/javascript">
			document.write('<script src="../../js/fix.js?rd=?rd=' + Math.random() + '"><\/script>');
		</script>
		<script type="text/javascript">
			link(['../../css/reset.css']);
		</script>
		<script type="text/javascript">
			script(['../../libs/picker/mui.dtpicker.js', '../../libs/region.js']);
		</script>
		<style type="text/css">
			.mui-input-row {
				padding: 0.05rem 0rem;
				height: auto !important;
			}

			#btnFrom {
				height: 40px;
				display: block !important;
				margin-left: 15px;
				background-color: #47BAFE;
				border-color: #47BAFE;
				width: calc(100% - 30px) !important;
			}

			#btnFrom:active {
				background: #0062CC;
				border-color: #0062CC;

			}

			input[type="text"],
			input[type="number"] {
				font-size: 0.14rem;
				text-align: right;
				padding: 0rem;
				float: inherit;
				margin: 0rem;
				height: auto;
				height: 0.5rem !important;
				border: none;
			}

			.mui-input-group .mui-input-row:after {
				left: 0.1rem;
			}

			.mui-input-row label {
				display: block;
				font-size: 12px;
				color: #999999;
				margin-left: 0.1rem;
				padding: 0rem;
				float: inherit;
			}

			.img {
				height: 0.4rem;
				width: 0.4rem;
				margin-left: 0.2rem;
			}

			.mui-table-view {
				margin-top: 20px;
			}

			.mui-table-view span.mui-pull-right {
				color: #999;
			}

			.mui-table-view-divider {
				background-color: #efeff4;
				font-size: 14px;
			}

			.mui-table-view-divider:before,
			.mui-table-view-divider:after {
				height: 0;
			}


			.head-img,#wechat-img {
				width: 0.4rem;
				height: 0.4rem;
			}

			#head-img,#wechat-img {
				position: absolute;
				bottom: 0.1rem;
				right: 0.3rem;
				width: 0.5rem;
				height: 0.5rem;
			}

			.mui-table-view-cell a {
				padding: 0px 0.15rem !important;
				line-height: 0.5rem;
				height: 0.5rem;
				padding-right: 0rem;
			}
			.mui-navigate-right:after, .mui-push-right:after{
				right: 0.1rem;
				font-weight: bold;
			}
		</style>
	</head>

	<body>
		<div id="contentInfo"  style="display: none;">
		
	<!-- 	<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">个人信息</h1>
		</header> -->
		<div class="mui-content">
			<ul class="mui-table-view">
			<li class="mui-table-view-cell" id="head_ImgObj"  style="height: auto;">
							<a class="mui-navigate-right" id="head" style="height: 0.7rem; line-height: 0.7rem;" >头像
					<img class="head-img mui-action-preview" src="../../fonts/iconfont/upload.png" id="head-img" />
															</a>
							</li> 
				<li class="mui-table-view-cell">
					<a>姓名<span class="mui-pull-right">
							<input type="text" id="name" placeholder="必填">
						</span></a>
				</li>

				<li class="mui-table-view-cell">
					<a>微信账号<span class="mui-pull-right">
							<input type="text" id="wechat_no" placeholder="必填">
						</span></a>
				</li>

				<li class="mui-table-view-cell" id="wechatImgObj" style="height: auto;">
					<a id="head " class="mui-navigate-right" style="height: 0.7rem; line-height: 0.7rem;">微信二维码
						<img class="head-img mui-action-preview" src="../../fonts/iconfont/upload.png" id="wechat-img" />
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a>手机号<span class="mui-pull-right">
							<input type="number" id="phone_no" placeholder="必填">
						</span></a>
				</li>
			</ul>
			<ul class="mui-table-view">
		

				<li class="mui-table-view-cell ">
					<a style="padding-right: 0px !important;direction: rtl;">性别<span class="mui-pull-right" style="width: 70%; ">
							<select style="margin: 0rem;" id="sex">
								<option value="M">男</option>
								<option value="F">女</option>
							</select>
						</span></a>
				</li>
				<li class="mui-table-view-cell " style="height: auto;display: flex;align-items: center;">
					<label class="mui-col-xs-3 mui-pull-left label_lineh">所在城市</label>
					<a id='region' class="mui-col-xs-9 mui-pull-left label_lineh" style="text-align: right;margin: -11px 0px;padding-right: 0rem !important;">
						<span class="cor-999" id="cityName">请选择</span>
					</a>
				</li>
				<li class="mui-table-view-cell">
					<a>所属公司<span class="mui-pull-right">
							<input type="text" id="company" placeholder="选填">
						</span></a>
				</li>
				<li class="mui-table-view-cell">
					<a>职务<span class="mui-pull-right">
							<input type="text" id="zhiwu" placeholder="选填">
						</span></a>
				</li>
				<li style="position: relative;overflow: hidden; padding: 11px 15px;">
					<lable style="display: block;">个人简介</lable>
					<textarea id="grjj" placeholder="选填" rows="" cols="" style="color: #999;padding-left: 0rem; border:none;font-size: 0.14rem;"></textarea>
					</span>
				</li>
			</ul>
             <p></p>
			<button type="button" id="btnFrom" class="mui-btn mui-btn-blue">保存</button>
          <br>
		</div>	
		</div>

		<script type="text/javascript">
			//必须顺序加载
			script();
		</script>
		<script type="text/javascript">
			mui.init();
			var files = null;
			var filesHead=null;
			mui.plusReady(function() {
				//隐私设置
				initPicker();
				storage.init();
				storageUser = kidstorageuser.getInstance();
				document.getElementById("name").value = storageUser.NickName == "" ? "" : storageUser.NickName;
				document.getElementById("wechat_no").value = storageUser.wechatNo == "" ? "" : storageUser.wechatNo;
				document.getElementById("phone_no").value = storageUser.TelNo == "" ? "" : storageUser.TelNo;
				document.getElementById("region").innerHTML = storageUser.city == "" ? "<span style='color:#999'>请选择</span>" : storageUser.city;
				document.getElementById("company").value = storageUser.company == "" ? "" : storageUser.company;
				document.getElementById("zhiwu").value = storageUser.positionTitle == "" ? "" : storageUser.positionTitle;
				document.getElementById("grjj").value = storageUser.Signature == "" ? "" : storageUser.Signature;
				if(storageUser.ImgUr==""){
						document.getElementById("head-img").setAttribute("src","../../fonts/iconfont/upload.png")
				}else{
							 var filename = storageUser.ImgUrl.substring(storageUser.ImgUrl.lastIndexOf("/") + 1, storageUser.ImgUrl.length);  
					var relativePath = "_doc/headimg/" + filename;  
					//判断本地是否存在此图片
					plus.io.resolveLocalFileSystemURL(relativePath , function(entry) {
						//存在就直接设置图片src
							var sd_path = plus.io.convertLocalFileSystemURL(relativePath);  
							document.getElementById("head-img").setAttribute("src",sd_path);
							//转成手机绝对路径
					},function(e){
						document.getElementById("head-img").setAttribute("src",storageUser.ImgUrl);
					})
				}
				document.getElementById("wechat-img").setAttribute("src", storageUser.wechatImg == "" ?"../../fonts/iconfont/upload.png" : storageUser.wechatImg)

				if (storageUser.sex == "女") {
					document.getElementById('sex').value = "F";
				} else {
					document.getElementById('sex').value = "M";
				}
				setTimeout(function(){
					document.getElementById("contentInfo").style.display="block";
				},50);
				//appPage.closeLogin();	
			});

			function initPicker(defaultVal) {
				var regionobj = document.getElementById("region");

				regionPicker = new mui.PopPicker({
					layer: 3
				});

				regionPicker.setData(region);
				if (defaultVal != null && defaultVal != "") {
					var vals = defaultVal.split("-");
					console.log(JSON.stringify(postData));
					regionPicker.pickers[0].setSelectedValue(vals[0]);
					regionPicker.pickers[1].setSelectedValue(vals[1]);
					regionPicker.pickers[2].setSelectedValue(vals[2]);
					// setTimeout("initSelectData()", 100);
				}

				regionobj.addEventListener("click", function() {
					regionPicker.show(function(items) {
						var op1 = (items[0] || {});
						var op2 = (items[1] || {});
						var op3 = (items[2] || {});
						if (op1.value == 0) {
							regionobj.innerText = (items[0] || {}).text;
						} else {
							regionobj.innerText = (items[0] || {}).text + " - " + (items[1] || {}).text + " - " + (items[2] || {}).text;
						}
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				});
			}
			document.getElementById("wechatImgObj").addEventListener("tap", function() {
				plus.gallery.pick(function(p) {
					  plus.io.resolveLocalFileSystemURL( p, function( entry ) { 
						  entry.file( function(file){  
							  var max_kb = 3*1048576;  
							  if(file.size>max_kb){  
								 mui.toast("图片过大");  
							  }else{
								  	document.getElementById("wechat-img").setAttribute("src", p);
								  var n = p.substr(p.lastIndexOf('/') + 1);
								  files = p;
							  }
						  })
					  })
				
				});
			})
			document.getElementById("head_ImgObj").addEventListener("tap", function() {
				plus.gallery.pick(function(p) {
					   plus.io.resolveLocalFileSystemURL( p, function( entry ) { 
							entry.file( function(file){  
								var fileReader = new plus.io.FileReader();  
								//alert("getFile:" + JSON.stringify(file));  
								//大于500kb  
								var max_kb = 5*1048576;  
								if(file.size>max_kb){  
									//压缩
									mui.toast('图片不能大于5M');
								// plus.zip.compressImage({
								// 		src:entry.fullPath,
								// 		dst:"_doc/a.jpg",
								// 		 format: 'jpg',  
								// 		quality: 100 
								// 	},function(e) {
								// 		 document.getElementById("head-img").setAttribute("src", "_doc/a.jpg");
								// 		 // var n = p.substr(p.lastIndexOf('/') + 1);
								// 		 filesHead = "_doc/a.jpg";
								// 		// mui.toast("压缩失败!");
								// 	},function(error) {
								// 		mui.toast("压缩失败!"+error);
								// 		// alert("Compress error!");
								// });
								}else{  
									document.getElementById("head-img").setAttribute("src", p);
									var n = p.substr(p.lastIndexOf('/') + 1);
									filesHead = p;
								};  
							} );  
						}, function ( e ) {  
							alert( "图片读取失败: " + e.message );  
							
					});  
				
				});

			})
			document.getElementById("btnFrom").addEventListener("tap", function() {
				plus.nativeUI.showWaiting("请稍等...");
				storage.init();
				storageUser = kidstorageuser.getInstance();
				baseStorage = kidstorage.getInstance("baseStorageDate");
				let name = document.getElementById("name").value;
				let wechat_no = document.getElementById("wechat_no").value;
				let tel_no = document.getElementById("phone_no").value;
				let obj = document.getElementById("sex");
				var index = obj.selectedIndex;
				let sex = obj.options[index].text;
				let city = document.getElementById("region").innerText;
				let company = document.getElementById("company").value;
				let zhiwu = document.getElementById("zhiwu").value;
				let grjj = document.getElementById("grjj").value;
				if (name == "" || wechat_no == "" || tel_no == "") {
					mui.toast("请填写完整");
					return;
				} else {
					if (files == null && storageUser.wechatImg == null) {
						mui.toast('请上传微信二维码！');
						return;
					}
					var task = plus.uploader.createUpload("http://118.25.184.62:8000/cmdb/updateSalesInfo/", {
							method: 'POST'
						},
						function(t, status) { //上传完成
							if (status == 200) {
								let wechat_img;
								let profile_img;
								if (JSON.parse(t.responseText).DATASET[0].wechat_img == "") {
									wechat_img = storageUser.wechatImg;
								} else {
									wechat_img = JSON.parse(t.responseText).DATASET[0].wechat_img;
								}
							if (JSON.parse(t.responseText).DATASET[0].profile_img == "") {
									profile_img = storageUser.ImgUrl;
								} else {
									profile_img = JSON.parse(t.responseText).DATASET[0].profile_img;
								}
					
								
								// alert("云U型");
								var storageData = {
									PlayerId: storageUser.UId,
									Mobile: tel_no,
									NickName: name,
									imgurl: profile_img,
									SelfdomSign: grjj,
									tel_no: tel_no,
									wechat_no: wechat_no,
									wechat_img: wechat_img,
									profile_img:profile_img,
									sex: sex,
									duty: zhiwu,
									company: company,
									city: city
									//cityid:data.CityId
								}
								storageUser.login(storageData);
									let webviewshare=plus.webview.getWebviewById("insurance/customerShare.html");
										let webviewMine=plus.webview.getWebviewById("mine/mine.html");
								mui.fire(webviewMine, 'refreshPage2',{img:profile_img});
									// mui.toast('上传成功：'+t.responseText);
										mui.back();	
								mui.fire(webviewshare, 'getcardinfo', storageData);
								// baseStorage.setItem("user", undefined, storageData);
								plus.storage.setItem('uploader', t.responseText);
								plus.nativeUI.closeWaiting();

								// clicked('uploader_ret.html');
							} else {
								mui.toast('上传失败：' + status);
								plus.nativeUI.closeWaiting();
							}
						}
					);
					task.addData('sales_id', storageUser.UId);
					task.addData('user_nm', name);
					task.addData('tel_no', tel_no);
					task.addData('wechat_no', wechat_no);
					task.addData('sex', sex);
					task.addData('city', city);
					task.addData('profile', grjj);
					task.addData('company', company);
					task.addData('title', zhiwu);
					task.addFile(files, {
						key: "myfile"
					});
					task.addFile(filesHead, {
						key: "myfile_profile"
					});
					task.start();
				}
			})
		</script>
	</body>

</html>
